package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.common.persistence.model.BillCheck;
import com.stylefeng.guns.modular.system.service.IBillCheckService;

/**
 * 历史对账控制器
 *
 * @author fengshuonan
 * @Date 2018-03-23 10:50:08
 */
@Controller
@RequestMapping("/billCheck")
public class BillCheckController extends BaseController {

    private String PREFIX = "/system/billCheck/";

    @Autowired
    private IBillCheckService billCheckService;

    /**
     * 跳转到历史对账首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "billCheck.html";
    }

    /**
     * 跳转到添加历史对账
     */
    @RequestMapping("/billCheck_add")
    public String billCheckAdd() {
        return PREFIX + "billCheck_add.html";
    }

    /**
     * 跳转到修改历史对账
     */
    @RequestMapping("/billCheck_update/{billCheckId}")
    public String billCheckUpdate(@PathVariable Integer billCheckId, Model model) {
        BillCheck billCheck = billCheckService.selectById(billCheckId);
        model.addAttribute("item",billCheck);
        LogObjectHolder.me().set(billCheck);
        return PREFIX + "billCheck_edit.html";
    }

    /**
     * 获取历史对账列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return billCheckService.selectList(null);
    }

    /**
     * 新增历史对账
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BillCheck billCheck) {
        billCheckService.insert(billCheck);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除历史对账
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer billCheckId) {
        billCheckService.deleteById(billCheckId);
        return SUCCESS_TIP;
    }

    /**
     * 修改历史对账
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BillCheck billCheck) {
        billCheckService.updateById(billCheck);
        return super.SUCCESS_TIP;
    }

    /**
     * 历史对账详情
     */
    @RequestMapping(value = "/detail/{billCheckId}")
    @ResponseBody
    public Object detail(@PathVariable("billCheckId") Integer billCheckId) {
        return billCheckService.selectById(billCheckId);
    }
}
